package com.lz.sports.utils

import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import android.widget.Toast
import com.lz.library.extension.APP
import com.lz.library.extension.dp2px
import com.lz.sports.R

object ToastUtils {

    fun showMyToast(text: String, duration: Int) {
        val toast = Toast(APP)
        val root: View = LayoutInflater.from(APP).inflate(R.layout.toast_usb, null, false)
        val tv = root.findViewById<TextView>(R.id.tv)
        toast.setGravity(Gravity.BOTTOM, 0, 70.dp2px())
        toast.duration = duration
        tv.text = text
        toast.view = root
        toast.show()
    }

    fun showMyToast(textResId: Int, duration: Int = Toast.LENGTH_LONG) {
        showMyToast(APP.getString(textResId), duration)
    }

    fun showSuccess(text: String, duration: Int) {
        val toast = Toast(APP)
        val root: View = LayoutInflater.from(APP).inflate(R.layout.toast_sure_sucess, null, false)
        val tv = root.findViewById<TextView>(R.id.tv)
        toast.setGravity(Gravity.CENTER, 0, 0)
        toast.duration = duration
        tv.text = text
        toast.view = root
        toast.show()
    }

    fun showSuccess(textResId: Int, duration: Int = Toast.LENGTH_LONG) {
        showSuccess(APP.getString(textResId), duration)
    }

}